open_sound_device
This function opens an audio device for playing sounds.
bool open_sound_device(int device_id)
Parameters:
device_id
The ID of the device to be opened.
Return value:
true on success, false on failure.
Remarks:
The device ID is 0-based, and matches the allotted index in the array returned by the list_sound_devices function.
To use a different device to the default, the device must be opened before any call to the load or stream methods in the sound object. If this is not done, the default device that is selected in the Control Panel will be used.
The engine runs off one master device only, and the device cannot be changed once it has been opened (either by an explicit call to this function or implicitly when either the stream or load method of any sound object is called for the first time).
Example:
// Play a sound and explicitly specify a device.
void main()
{
sound test;
string[] devices;
bool success;
devices=list_sound_devices();
if(devices.length()==0)
{
alert("Error", "No devices can be found on your system.");
exit();
}
if(devices.length()==1)
{
alert("Information", "Only one device can be found on your system and will now be used.");
}
success=open_sound_device(devices.length()-1);
if(!success)
{
alert("Error", "Device number " + devices.length() + " could not be opened, so reverting back to the default.");
}
test.load("c:/windows/media/ding.wav");
if(!test.active)
{
alert("Error", "Cannot find one of your windows sounds.");
exit();
}
test.play_wait();
test.close();
}